package com.stox.charting.ui.swing.widget;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.stox.charting.ui.swing.model.ChartSpan;
import com.stox.charting.ui.swing.model.price.PriceChartModel;
import com.stox.charting.ui.swing.view.ChartingInternalFrameView;
import com.stox.core.ui.swing.wrapper.JComboBox;

public class ChartSpanComboBox extends JComboBox<ChartSpan> implements ActionListener{
	private static final long serialVersionUID = -5862084182039059233L;

	public ChartSpanComboBox() {
		super(ChartSpan.values());
		setSelectedItem(ChartSpan.YEAR1);
		addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		ChartingInternalFrameView view = ChartingInternalFrameView.getLastSelectedView();
		if(view != null){
			PriceChartModel<?> model = view.getPriceChartView().getPriceChart().getModel();
			model.setChartSpan((ChartSpan)getItemAt(getSelectedIndex()));
		}
	}
	
}
